package cn.com.dycc.party_work.education_log.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.party_work.education_log.entity.EducationLog;
import cn.com.dycc.party_work.education_log.entity.EducationLogInfo;
import cn.com.dycc.party_work.education_log.param.EducationLogParam;
import cn.com.dycc.party_work.education_log.service.EduLogNotFoundException;
import cn.com.dycc.party_work.education_log.service.EducationLogService;
import cn.com.dycc.util.JsonObjectResult;
/**
 * 
 * Description: 
 * Author: Liket
 * Version: 1.0
 * Create Date Time: 2018年7月4日 上午9:30:54.
 * Update Date Time: 
 * @see
 */
@Controller
@RequestMapping("/education/log")
public class EducationLogController extends BaseController{
	@Resource
	private EducationLogService eduService;

	@RequestMapping("/add.do")
	@ResponseBody
	public JsonObjectResult addEduLog(EducationLog eduLog,HttpServletRequest req){
		int n = eduService.addEduLog(eduLog, req);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/findone.do")
	@ResponseBody
	public JsonObjectResult findEduLog(String log_id,HttpServletRequest req){
		EducationLog edu = eduService.findEduLog(log_id, req);
		return new JsonObjectResult(edu);
	}
	
	@RequestMapping("/find.do")
	@ResponseBody
	public JsonObjectResult findEduLogByParam(EducationLogParam param,HttpServletRequest req){
		String count = eduService.findEduLogCount(param, req);
		List<EducationLogInfo> list = eduService.findEduLogByParam(param, req);
		return new JsonObjectResult(count,list);
	}
	@RequestMapping("/findu.do")
	@ResponseBody
	public JsonObjectResult findEduLogU(EducationLogParam param,HttpServletRequest req){
		HttpSession session = req.getSession();
		String user_id = (String) session.getAttribute("id");
		param.setUser_id(user_id);
		String count = eduService.findEduLogCount(param, req);
		List<EducationLogInfo> list = eduService.findEduLogByParam(param, req);
		return new JsonObjectResult(count,list);
	}
	
	@RequestMapping("/findd.do")
	@ResponseBody
	public JsonObjectResult findEduLogD(EducationLogParam param,HttpServletRequest req){
		HttpSession session = req.getSession();
		String dept_id = (String) session.getAttribute("dept_id");
		param.setDept_id(dept_id);
		String count = eduService.findEduLogCount(param, req);
		List<EducationLogInfo> list = eduService.findEduLogByParam(param, req);
		return new JsonObjectResult(count,list);
	}
	
	@RequestMapping("/findud.do")
	@ResponseBody
	public JsonObjectResult findEduLogUD(EducationLogParam param,HttpServletRequest req){
		HttpSession session = req.getSession();
		String dept_id = (String) session.getAttribute("dept_id");
		String user_id = (String) session.getAttribute("id");
		param.setUser_id(user_id);
		param.setDept_id(dept_id);
		String count = eduService.findEduLogCount(param, req);
		List<EducationLogInfo> list = eduService.findEduLogByParam(param, req);
		return new JsonObjectResult(count,list);
	}
	
	@RequestMapping("/delete.do")
	@ResponseBody
	public JsonObjectResult deleteEduLog(String log_ids[],HttpServletRequest req){
		int n = eduService.deleteEduLog(log_ids, req);
		return new JsonObjectResult(n);
	}
	
	@ExceptionHandler(EduLogNotFoundException.class)
	@ResponseBody
	public JsonObjectResult eduException(EduLogNotFoundException e){
		e.printStackTrace();
		return new JsonObjectResult(89,e);
	}
}
